<?php

namespace App\Criteria\System\SystemCode;

use App\Libs\Tools\DataTables;
use Illuminate\Support\Facades\Input;
use Prettus\Repository\Contracts\CriteriaInterface;
use Prettus\Repository\Contracts\RepositoryInterface;

/**
 * Class SystemCodeBaseQueryCriteria
 * @package namespace App\Criteria\System\SystemCode;
 */
class SystemCodeBaseQueryCriteria implements CriteriaInterface
{
    public function apply($model, RepositoryInterface $repository)
    {
        $type=Input::get('type');
        $type_name=Input::get('type_name');
        if($type){$model = $model->where('type','like', '%'.$type.'%');}
        if($type_name){$model = $model->where('type_name','like', '%'.$type_name.'%');}
        $order_column_tag=DataTables::get_order_column_tag();
        if(!is_null($order_column_tag)){
            $model->orderBy($order_column_tag['order_column'],$order_column_tag['order_type']);
        }
        return $model;
    }


}
